package cn.wlh.learn.webmagic.processor;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.processor.PageProcessor;

/**
 * https://www.cnblogs.com/zhhiyp/p/9064347.html
 */
public class DaZhongBJProcessor implements PageProcessor {
    private final static Log logger = LogFactory.get();

    private Site site = Site.me().setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0").setRetryTimes(3).setSleepTime(1000);
    @Override
    public void process(Page page) {
        logger.info("html=[{}]\n\n",page.getHtml());
    }


    @Override
    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
        Spider.create(new DaZhongBJProcessor())
                .addUrl("https://www.dazhongbaojian0.com/item-list-catid-5.html")  //设置爬的url
                .addPipeline(new ConsolePipeline()) //会output到控制台...在这里并不需要,因为持久化到数据库了
                .thread(5)
                .run();
    }
}